package ocbn.remotelab.util;

import java.util.Vector;


/**
 * NOTE: This class does not work and is not currently part of the project. 
 * Please do not mark this.
 *
 * Originally wrote this for validating the fields of MassSpectrometerStateEvent
 * class, but due to the lack of reflection in Java ME, this doesn't work
 * properly. This might be useful for some other purposes in the future.
 *
 * @author Ke Li
 */

public class ObjectIntegrityValidator {

    Vector validationCriteria;
    Vector invalidationCriteria;
    public ObjectIntegrityValidator(){
        validationCriteria = new Vector();
        invalidationCriteria = new Vector();
    }

    public void addValidationCriterion(Object field, Object validValue){
        Vector criterion = new Vector();
        criterion.addElement(field);
        criterion.addElement(validValue);
        validationCriteria.addElement(criterion);
    }

    public void addInvalidationCriterion(Object field, Object invalidValue){
        Vector criterion = new Vector();
        criterion.addElement(field);
        criterion.addElement(invalidValue);
        invalidationCriteria.addElement(criterion);
    }

    public boolean validate(){
        for(int i = 0; i < validationCriteria.size(); i++){
            if(!((Vector)(validationCriteria.elementAt(i))).firstElement().
                    equals(((Vector)(validationCriteria.elementAt(i))).
                    lastElement())){
                return false;
            }
        }
        for(int i = 0; i < invalidationCriteria.size(); i++){
            if(((Vector)(invalidationCriteria.elementAt(i))).firstElement().
                    equals(((Vector)(invalidationCriteria.elementAt(i))).
                    lastElement())){
                return false;
            }
        }
        return true;
    }

}